//
//  AboutJingjingViewController.m
//  jingjing2.0
//
//  Created by apple on 16/5/22.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "AboutJingjingViewController.h"

@interface AboutJingjingViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UILabel     *_tipLabel;
}
@property (nonatomic,strong)UITableView * mainTableView;
@property (nonatomic,strong)NSDictionary * dataDic;
@end

@implementation AboutJingjingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = GRAYCOLOR;
    self.title = @"关于净净";
    [self.view addSubview:self.mainTableView];
    [self requestTheData];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [GeneralTool hideTabBar];
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [GeneralTool showTabBar];
}
-(void)requestTheData
{
    NSString *timestamp=[GeneralTool gettimestamp];
    
    NSDictionary *dic=@{@"TypeName":@"IOS",@"Timestamp":timestamp};//1 代表已领取
    NSString *sign=[GeneralTool GetSin:dic];
    //    http://121.43.224.215:3722/Activity/ColorEggsList/1150612474061/0/1463928172/9DF876B3BAFF1DBE98B6A1BEB739517F
    NSString *urlString=[NSString stringWithFormat:@"Common/Version/%@/%@/%@",@"IOS",timestamp,sign];
    [RequestTool requestDataWithType:@"get" andUrlString:urlString andParameters:nil andRequestFinished:^(id responses, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        if ([responses[@"IsSuccess"]intValue]==1) {
            _dataDic = [responses objectForKey:@"ReturnObject"];
            [_mainTableView reloadData];
            //判断是不是最新版本
        }else
        {
            [MBProgressHUD showError:@"获取信息失败"];
        }
        
        
        }];

}
-(UITableView *)mainTableView
{
    if (!_mainTableView)
    {
        _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,kWidth, kHeight) style:UITableViewStylePlain];
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _mainTableView.tableHeaderView = [self getTheTableHeaderView];
        _mainTableView.backgroundColor = GRAYCOLOR;
        _mainTableView.tableFooterView = [UIView new];//设置当数据不多的时候，下面无cell
        _mainTableView.sectionHeaderHeight = 0;
        _mainTableView.sectionFooterHeight = 0;
    }
    return _mainTableView;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.backgroundColor = [UIColor whiteColor];
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        UILabel *detail=[[UILabel alloc]initWithFrame:CGRectMake(cell.frame.size.width - 190, 7, 180, 30)];
        detail.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
        detail.textColor=[UIColor lightGrayColor];
        detail.font=[UIFont systemFontOfSize:13];
        detail.textAlignment=NSTextAlignmentRight;
        detail.tag = 111;
        [cell addSubview:detail];
    }
    UILabel * detailLable = (UILabel *)[cell viewWithTag:111];
    if (indexPath.row == 0)
    {
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        NSString * currentVerson = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        cell.textLabel.text = [NSString stringWithFormat:@"当前版本%@",currentVerson];
        if ([currentVerson isEqualToString:[_dataDic objectForKey:@"VerName"]])
        {
            detailLable.text = @"已是最新版本 >";
        }else
        {
            detailLable.text = @"不是最新版本 >";
        }
    }else
    {
        cell.textLabel.text = @"分享好友";
        detailLable.text = @"独享不如与众享 >";
    }
    return cell;

}
-(UIView *)getTheTableHeaderView
{
    UIView * backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 200)];
    backView.backgroundColor = GRAYCOLOR;
    
    UIImageView * logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 173/2.0, 170/2.0)];
    logoImageView.center = CGPointMake(backView.frame.size.width/2.0, backView.frame.size.height/2.0-10);
    logoImageView.image = [UIImage imageNamed:@"logo"];
    [backView addSubview:logoImageView];
    
    _tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(logoImageView.frame), kWidth, 20)];
    _tipLabel.font = [UIFont systemFontOfSize:14];
    _tipLabel.textAlignment = NSTextAlignmentCenter;
    
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString * currentVerson = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    _tipLabel.text = [NSString stringWithFormat:@"净净洗衣%@",currentVerson];
    [backView addSubview:_tipLabel];
    
    return backView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
